package de.bht.netviz.ipsaver.lookup.model;

import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Implementierung des ILookupData Interfaces für den Dienst von freegeoip.net.
 * 
 * @author Marius Hentschel
 * @since  2012/11/05
 */
@Entity
@Table(name="LOOKUPDATA", schema="DATA")
@XmlRootElement(name="Response")
public class FreeGeoLookupData implements ILookupData {
   
   private long id;
   
	private String regionCode;
	private String city;
   private String countryCode;
   private String countryName;
   private String ip;
   private String lat;
   private String lon;
   private String regionName;
   private String zip;
   private String metroCode;

   public FreeGeoLookupData() {
   }

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   public long getId() {
      return id;
   }

   @XmlElement(name = "City")
   @Override
   public String getCity() {
      return this.city;
   }

   @XmlElement(name = "CountryCode")
   @Transient
   @Override
   public String getCountryCode() {
      return this.countryCode;
   }

   @XmlElement(name = "CountryName")
   @Override
   public String getCountryName() {
      return this.countryName;
   }

   @XmlElement(name = "Ip")
   @Override
   public String getIp() {
      return this.ip;
   }

   @XmlElement(name = "Latitude")
   @Override
   public String getLat() {
      return this.lat;
   }

   @XmlElement(name = "Longitude")
   @Override
   public String getLon() {
      return this.lon;
   }

   @XmlElement(name = "RegionName")
   @Override
   public String getRegionName() {
      return this.regionName;
   }
   
   @XmlElement(name="RegionCode")
   @Transient
   public String getRegionCode() {
      return regionCode;
   }

   public void setRegionCode(String geoplugin_regionCode) {
      this.regionCode = geoplugin_regionCode;
   }


   @XmlElement(name="MetroCode")
   @Transient
   public String getMetroCode() {
      return metroCode;
   }

   public void setMetroCode(String metroCode) {
      this.metroCode = metroCode;
   }

   @XmlElement(name="ZipCode")
   @Transient
   public String getZip() {
      return zip;
   }

   public void setZip(String zip) {
      this.zip = zip;
   }
   
   public void setId(long id) {
      this.id = id;
   }
   
   public void setCity(String city) {
      this.city = city;
   }

   public void setCountryCode(String countryCode) {
      this.countryCode = countryCode;
   }

   public void setCountryName(String countryName) {
      this.countryName = countryName;
   }

   public void setIp(String ip) {
      this.ip = ip;
   }

   public void setLat(String lat) {
      this.lat = lat;
   }

   public void setLon(String lon) {
      this.lon = lon;
   }

   public void setRegionName(String regionName) {
      this.regionName = regionName;
   }

   @Override
   public int hashCode() {
      int hash = 7;
      hash = 23 * hash + (int) (this.id ^ (this.id >>> 32));
      hash = 23 * hash + Objects.hashCode(this.city);
      hash = 23 * hash + Objects.hashCode(this.countryName);
      hash = 23 * hash + Objects.hashCode(this.ip);
      hash = 23 * hash + Objects.hashCode(this.lat);
      hash = 23 * hash + Objects.hashCode(this.lon);
      hash = 23 * hash + Objects.hashCode(this.regionName);
      return hash;
   }

   @Override
   public boolean equals(Object obj) {
      if (obj == null) {
         return false;
      }
      if (getClass() != obj.getClass()) {
         return false;
      }
      final FreeGeoLookupData other = (FreeGeoLookupData) obj;
      if (this.id != other.id) {
         return false;
      }
      if (!Objects.equals(this.city, other.city)) {
         return false;
      }
      if (!Objects.equals(this.countryName, other.countryName)) {
         return false;
      }
      if (!Objects.equals(this.ip, other.ip)) {
         return false;
      }
      if (!Objects.equals(this.lat, other.lat)) {
         return false;
      }
      if (!Objects.equals(this.lon, other.lon)) {
         return false;
      }
      if (!Objects.equals(this.regionName, other.regionName)) {
         return false;
      }
      return true;
   }
   
   
   @Override
   public String toString() {
      return "FreeGeoLookupDataString[ ip = " + this.ip + ", metroCode = " 
           + this.metroCode + ", city = " + this.city + ", zip = "
           + this.zip + ", country = " + this.countryName + " ("
           + this.countryCode + "), coordinates = " + this.lat + "° / "
           + this.lon + "°, region = " + this.regionName + " ]";
   }
}
